package cn.sumpu.app.coolsk.web.mvc.index;

import java.util.List;

import javax.servlet.http.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import cn.sumpu.app.coolsk.biz.*;
import cn.sumpu.app.coolsk.domain.*;

@Controller
public class IndexController {

//	@Autowired
//	private ChannelBiz channelBiz;
	@Autowired
	private ContentBiz contentBiz;
	@Autowired
	private InfoBiz infoBiz;
	@Autowired
	private DiscussBiz discussBiz;
	
	//进入首页
	@RequestMapping(value = "/welcome.htm")
	public String enterLogin(HttpServletRequest request, HttpServletResponse response) {
		//取得首页内容
		contentBiz.getIndexContent(request);
		return "v1/index/index";
	}
	
	//进入稿件详细页面
	@RequestMapping(value = "/infoDetail.htm")
	public String infoDetail(HttpServletRequest request, HttpServletResponse response,
			String id, String cid){
		try{
			//取得稿子
			Info info = infoBiz.getInfoById(id);
			request.setAttribute("info", info);
			//浏览加一
			infoBiz.updateInfoViews(id, 1);
			
			
			//官方攻略
			List<Content> guanFangGongLue = contentBiz.getContentByChannel("392eb81a-3430-4a7e-9564-62c2d83e174e", 1);
			request.setAttribute("guanFangGongLue", guanFangGongLue);
			//推荐攻略
			List<Content> tuiJianGongLue = contentBiz.getContentByChannel("90ca6110-f92b-49bf-a12f-8d4d5180d6d4", 10);
			request.setAttribute("tuiJianGongLue", tuiJianGongLue);
			//最新攻略
			List<Content> zuiXinGongLue = contentBiz.getContentByChannel("b058dcb5-5fc3-4279-95e0-b790d0852660", 10);
			request.setAttribute("zuiXinGongLue", zuiXinGongLue);
			//国内攻略
			List<Content> guoNeiGongLue = contentBiz.getContentByChannel("109dfbd4-c1d7-4ea8-9d76-2756b061289f", 7);
			request.setAttribute("guoNeiGongLue", guoNeiGongLue);
			//出境攻略
			List<Content> chuJingGongLue = contentBiz.getContentByChannel("769c4862-b628-4e9b-82ec-8e7836fb5c1d", 7);
			request.setAttribute("chuJingGongLue", chuJingGongLue);
		}catch(Exception e){
			e.printStackTrace();
		}
		return "v1/index/infoDetail";
	}
	
	//进入点评页面
	@RequestMapping(value = "/review.htm")
	public String journey(HttpServletRequest request, HttpServletResponse response) {
		try{
			//取得点评首页的内容
			discussBiz.getIndexReview(request);
		}catch(Exception e){
			e.printStackTrace();
		}
		return "v1/index/review";
	}
	
}
